﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class login_Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btlogar_Click(object sender, EventArgs e)
    {
        if (tblogin.Text.Trim() == "" || tbsenha.Text.Trim() == "")
        {
            lbaviso.Text = "<p class=\"title\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*Os campos não estão preenchidos</p>";
        }
        else
        {
            LoginDomonio ld = new LoginDomonio();

            if (ld.LogarUsuario(tblogin.Text, tbsenha.Text, cb.Checked))
            {

                if (!string.IsNullOrEmpty(Request.QueryString["ReturnUrl"]))
                {
                    if (Request.QueryString["ReturnUrl"] == "/Chamados/login/")
                    {
                        Response.Redirect("~/Nova-Requisicao/");
                    }
                    else
                    {
                        Response.Redirect(Request.QueryString["ReturnUrl"]);
                    }
                }
                else
                    Response.Redirect("~/Nova-Requisicao/");
            }
            else
            {
                lbaviso.Text = "<p class=\"title\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*Usuário ou senha incorretos.</p>";
                tbsenha.Text = "";
            }
        }

    }
}